<template>
  <div class="content-legend">
    <p class="content-legend-title">
      {{ currentLegendData.name }}
    </p>
    <div class="color-bar">
      <div
        v-for="(item, index) in currentLegendData.levels"
        :key="index"
        class="color-bar-item"
      >
        <div
          class="color"
          :style="{ backgroundColor: currentTabData.color[index] }"
        ></div>
        <p class="text">{{ item }}</p>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { useTrafficStore } from '@/pages/traffic/store/store'

const trafficStore = useTrafficStore()
const currentTabData = computed(() => trafficStore.currentTabData)

const currentLegendData = computed(() => trafficStore.currentTabData)
</script>

<style scoped lang="scss">
.content-legend {
  min-width: 124px;
  max-height: 440px;
  position: absolute;
  left: 650px;
  bottom: 600px;
  z-index: 1200;
  padding: 10px;
  box-sizing: border-box;
  background: #f8f8f8;
  border-radius: 4px;
  border: 1px solid #4485cb;

  &-title {
    font-size: 14px;
    font-weight: 400;
    color: #000000;
    margin-bottom: 10px;
    white-space: nowrap;
    text-align: center;
  }

  .color-bar {
    display: flex;
    flex-direction: column;

    &-item {
      display: flex;
      align-items: center;
      justify-content: space-between;

      .color {
        width: 50px;
        height: 22px;
        background-color: #fff;
        margin-right: 4px;
      }

      .text {
        font-size: 12px;
        color: #000000;
        font-weight: 500;
        white-space: nowrap;
      }
    }
  }
}
</style>
